package com.tt.fashionWebSite.controller;

import com.tt.fashionWebSite.domain.ChiTietSanPham;
import com.tt.fashionWebSite.dto.*;
import com.tt.fashionWebSite.service.Ad_BillService;
import com.tt.fashionWebSite.service.Ad_DealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.text.ParseException;
import java.util.List;
import java.util.Map;

@Controller
public class Ad_DealController {
    @Autowired
    private Ad_DealService ad_dealService;

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/header/adDealCommon", method = RequestMethod.POST)
    public @ResponseBody
    JsonResponseDto<Integer> adminDeal(HttpServletRequest request, @RequestBody KhuyenMaiDto dealDto) {
        return new JsonResponseDto<Integer>(ad_dealService.adminDeal(dealDto));
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/ad_GetAllDeal", method = RequestMethod.GET)
    public @ResponseBody
    JsonResponseDto<List<KhuyenMaiDto>> getAllDeal(HttpServletRequest request) {
        return new JsonResponseDto<List<KhuyenMaiDto>>(ad_dealService.getAllDeal(), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/ad_GetAllDealDetail", method = RequestMethod.GET)
    public @ResponseBody
    JsonResponseDto<List<ChiTietKhuyenMaiDto>> getAllDealDetail(HttpServletRequest request) {
        return new JsonResponseDto<List<ChiTietKhuyenMaiDto>>(ad_dealService.getAllDealDetail(), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/toDealPage/{maKM}", method = RequestMethod.GET)
    public @ResponseBody
    ModelAndView toPageDeal(HttpServletRequest request, @PathVariable String maKM, Map<String, Object> map) throws ParseException {
        map.put("maKM", maKM);
        return new ModelAndView("admin/ad-deal-edit");
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/toDealDetailPage/{maCTKM}", method = RequestMethod.GET)
    public @ResponseBody
    ModelAndView toPageDealDetail(HttpServletRequest request, @PathVariable String maCTKM, Map<String, Object> map) throws ParseException {
        map.put("maCTKM", maCTKM);
        return new ModelAndView("admin/ad-deal-detail-edit");
    }

    @SuppressWarnings("rawtypes")
         @RequestMapping(value = "/admin/editDeal", method = RequestMethod.POST)
         public @ResponseBody
         JsonResponseDto<KhuyenMaiDto> getDealInfoEdit(HttpServletRequest request, @RequestBody KhuyenMaiDto dealDto) {
        return new JsonResponseDto<KhuyenMaiDto>(ad_dealService.getDealInfoEdit(dealDto), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/editDealDetail", method = RequestMethod.POST)
    public @ResponseBody
    JsonResponseDto<ChiTietKhuyenMaiDto> getDealDetailInfoEdit(HttpServletRequest request, @RequestBody ChiTietKhuyenMaiDto dealdetailDto) {
        return new JsonResponseDto<ChiTietKhuyenMaiDto>(ad_dealService.getDealDetailInfoEdit(dealdetailDto), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/registerDealEdit", method = RequestMethod.POST)
    public @ResponseBody
    JsonResponseDto<KhuyenMaiDto> registerDealEdit(HttpServletRequest request, @RequestBody KhuyenMaiDto dealDto) {
        return new JsonResponseDto<KhuyenMaiDto>(ad_dealService.registerDealEdit(dealDto), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/registerDealDetailEdit", method = RequestMethod.POST)
    public @ResponseBody
    JsonResponseDto<ChiTietKhuyenMaiDto> registerDealDetailEdit(HttpServletRequest request, @RequestBody ChiTietKhuyenMaiDto dealdetailDto) {
        return new JsonResponseDto<ChiTietKhuyenMaiDto>(ad_dealService.registerDealDetailEdit(dealdetailDto), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/getAllMemberShowInDeal", method = RequestMethod.GET)
    public @ResponseBody
    JsonResponseDto<List<ThongTinThanhVienDto>> getAllMemberShowInDeal(HttpServletRequest request) {
        return new JsonResponseDto<List<ThongTinThanhVienDto>>(ad_dealService.getAllMemberShowInDeal(), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/getAllMemberShowInDealCommon", method = RequestMethod.GET)
    public @ResponseBody
    JsonResponseDto<List<ThongTinThanhVienDto>> getAllMemberShowInDealCommon(HttpServletRequest request) {
        return new JsonResponseDto<List<ThongTinThanhVienDto>>(ad_dealService.getAllMemberShowInDealCommon(), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/getAllProductDetailCodeInDeal", method = RequestMethod.GET)
    public @ResponseBody
    JsonResponseDto<List<ChiTietSanPhamDto>> getAllProductDetailCodeInDeal(HttpServletRequest request) {
        return new JsonResponseDto<List<ChiTietSanPhamDto>>(ad_dealService.getAllProductDetailCodeInDeal(), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/getAllProductDetailShowInDetail", method = RequestMethod.GET)
    public @ResponseBody
    JsonResponseDto<List<ChiTietSanPhamDto>> getAllProductDetailShowInDetail(HttpServletRequest request) {
        return new JsonResponseDto<List<ChiTietSanPhamDto>>(ad_dealService.getAllProductDetailShowInDetail(), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/getAllDealDetailShowInDetail", method = RequestMethod.GET)
    public @ResponseBody
    JsonResponseDto<List<KhuyenMaiDto>> getAllDealDetailShowInDetail(HttpServletRequest request) {
        return new JsonResponseDto<List<KhuyenMaiDto>>(ad_dealService.getAllDealDetailShowInDetail(), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/getDataDetailOfDealCommon/{maKM}", method = RequestMethod.GET)
    public @ResponseBody
    JsonResponseDto<ChiTietKhuyenMaiDto> getDataDetailOfDealCommon(HttpServletRequest request, @PathVariable String maKM) throws ServletException, IOException {
        return new JsonResponseDto<ChiTietKhuyenMaiDto>(ad_dealService.getDataDetailOfDealCommon(maKM), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/insertProductDetailForDeal/{maKM}/{percent}", method = RequestMethod.POST)
    public @ResponseBody
    JsonResponseDto<Integer> insertProductDetailForDeal(HttpServletRequest request,@RequestBody List<ChiTietSanPhamDto> chiTietSanPhams, @PathVariable String maKM,  @PathVariable Float percent) throws ServletException, IOException {
        return new JsonResponseDto<Integer>(ad_dealService.insertProductDetailForDeal(chiTietSanPhams,maKM, percent));
    }

}
